﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using Semantics;

namespace GraphBase.Presentation
{
    /// <summary>
    /// 定义边的数据结构
    /// </summary>
    public class EdgePos
    {  
        //构造函数所用变量
        public PointF startPoint;//定义开始位置
        public PointF MiddlePoint;//曲线上的中间点位置
        public PointF endPoint;//定义结束位置
        public Edge pedge;
        public Rectangle rectangle;
        public float startAngle;
        public float sweepAngle;
        public float Arc_d;
        public PointF Ptext;//节点和边上的文字的位置 
        public PointF PArctext;
        public PointF PointArc_O;
        public float R;//弧所在圆的半径
        public EdgePos(Edge edge)
        {
            this.pedge = edge;
        }
        public EdgePos(Edge edge, PointF sp, PointF ep,PointF ptext)//画直线
        {
            pedge = edge;
            startPoint = sp;
            endPoint = ep;
            Ptext = ptext;
        }
        public EdgePos(Edge edge, PointF sp, PointF mp, PointF ep,float r,PointF ptext)//过三点的圆，半径，弧上的文字位置曲线
        {
            pedge = edge;
            startPoint = sp;
            MiddlePoint = mp;
            endPoint = ep;
            R = r;
            Ptext = ptext;
        }
        public EdgePos(Edge edge, Rectangle rect, float startangle, float sweepangle, PointF ptext,PointF sp,PointF ep,PointF op,float arcd)//圆弧，圆上的文字，圆心，半径
        {
            pedge = edge;
            rectangle = rect;
            startAngle = startangle;
            sweepAngle = sweepangle;
            PArctext = ptext;
            startPoint = sp;
            endPoint = ep;
            PointArc_O = op;
            Arc_d = arcd;
        }
        Pen pnline;
        public void DrawColorLineEdges(Graphics g, EdgePos edgept,int i)
        {
            AdjustableArrowCap myArrow = new AdjustableArrowCap(3, 5);
            float width = 1.0f;
            switch (i)
            {
                case 0:
                    pnline = new Pen(Color.Blue, width);
                    pnline.CustomEndCap = myArrow;
                    g.DrawLine(pnline, edgept.startPoint, edgept.endPoint);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Blue), edgept.Ptext);
                    break;
                case 1:
                    pnline = new Pen(Color.LightBlue, width);
                    pnline.CustomEndCap = myArrow;
                    g.DrawLine(pnline, edgept.startPoint, edgept.endPoint);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.DarkGreen), edgept.Ptext);
                    break;
                case 2:
                    pnline = new Pen(Color.LightGreen, width);
                    pnline.CustomEndCap = myArrow;
                    g.DrawLine(pnline, edgept.startPoint, edgept.endPoint);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.GreenYellow), edgept.Ptext);
                    break;
                case 3:
                    pnline = new Pen(Color.LightCoral, width);
                    pnline.CustomEndCap = myArrow;
                    g.DrawLine(pnline, edgept.startPoint, edgept.endPoint);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Olive), edgept.Ptext);
                    break;
                case -1:
                default:
                    pnline = new Pen(Color.Black, width);
                    pnline.CustomEndCap = myArrow;
                    g.DrawLine(pnline, edgept.startPoint, edgept.endPoint);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Black), edgept.Ptext);
                    break;
            }          
        }
        public void DrawColorArcEdges(Graphics g, EdgePos edgept, int i)
        {
            AdjustableArrowCap myArrow = new AdjustableArrowCap(4, 6);
            switch (i)
            {
                case 0:
                    pnline = new Pen(Color.Blue, 2.0f);
                    pnline.CustomEndCap = myArrow;
                    g.DrawArc(pnline, edgept.rectangle, edgept.startAngle, edgept.sweepAngle);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Blue), edgept.PArctext);
                    break;
                case 1://第一跳亮蓝色
                    pnline = new Pen(Color.LightBlue, 2.0f);
                    pnline.CustomEndCap = myArrow;
                    g.DrawArc(pnline, edgept.rectangle, edgept.startAngle, edgept.sweepAngle);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.DarkGreen), edgept.PArctext);
                    break;
                case 2://第二跳亮绿色
                    pnline = new Pen(Color.LightGreen, 2.0f);
                    pnline.CustomEndCap = myArrow;
                    g.DrawArc(pnline, edgept.rectangle, edgept.startAngle, edgept.sweepAngle);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.GreenYellow), edgept.PArctext);
                    break;
                case 3:
                    pnline = new Pen(Color.LightCoral, 2.0f);
                    pnline.CustomEndCap = myArrow;
                    g.DrawArc(pnline, edgept.rectangle, edgept.startAngle, edgept.sweepAngle);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Olive), edgept.PArctext);
                    break;
                case -1:
                default:
                    pnline = new Pen(Color.Black, 2.0f);
                    pnline.CustomEndCap = myArrow;
                    g.DrawArc(pnline, edgept.rectangle, edgept.startAngle, edgept.sweepAngle);
                    g.DrawString(edgept.pedge.FristLeaf.Class.Label, new Font("Arial", 9), new SolidBrush(Color.Black), edgept.PArctext);
                    break;
            }
        }

        public override string ToString()
        {
            return this.pedge.ToString();
        }
    }
}
